<template>
  <pro-layout
    v-model:openKeys="vdata.openKeys"
    v-model:selectedKeys="vdata.selectedKeys"
    v-model:collapsed="proLayoutObject.collapsed"
    layout="side"
    :active-name="$route.path"
    :nav-theme="vdata.theme"
    :sider-width="260"
    :menu-data="menuData"
    isMobile="true"
    :collapsed-button-render="false"
    :collapsed-width="80"
  >
    <router-view v-if="isRouterAlive" :proLayoutObject="proLayoutObject" />

    <!-- 菜单头部渲染插槽 -->
    <template #menuHeaderRender>
      <router-link
        :to="{ path: '/' }"
        style="display: flex; align-items: center"
      >
        <div v-if="!proLayoutObject.collapsed">
          <img
            v-if="vdata.theme === 'light'"
            :src="oemSiteInfo.sysLogoUrl"
            style="height: 30px"
          >
          <img
            v-else
            :src="
              oemSiteInfo.darkSysLogoUrl
                ? oemSiteInfo.darkSysLogoUrl
                : oemSiteInfo.sysLogoUrl
            "
            style="height: 30px"
          >
        </div>
        <div v-else>
          <img
            v-if="vdata.theme === 'light'"
            :src="oemSiteInfo.sysMinLogoUrl"
            style="height: 30px"
          >
          <img
            v-else
            :src="
              oemSiteInfo.darkSysMinLogoUrl
                ? oemSiteInfo.darkSysMinLogoUrl
                : oemSiteInfo.sysMinLogoUrl
            "
            style="height: 30px"
          >
        </div>
      </router-link>
    </template>

    <!-- 菜单底部换色按钮 -->
    <template #menuFooterRender>
      <div
        class="menu-footer"
        :class="{ 'menu-footer-dark': vdata.theme === 'dark' }"
        :style="{
          margin: proLayoutObject.collapsed ? '15px 15px 0' : '20px 25px 0'
        }"
        @click="vdata.theme = vdata.theme === 'dark' ? 'light' : 'dark'"
      >
        <i class="bi bi-circle-half" />
        <span v-if="!proLayoutObject.collapsed">
          切换至{{ vdata.theme === 'dark' ? '亮色' : '暗色' }}</span>
      </div>
    </template>

    <!-- 自定义顶部内容， 包括刷新按钮，面包屑 -->
    <template #headerContentRender>
      <div class="customhead">
        <div class="refash">
          <MenuUnfoldOutlined
            v-if="proLayoutObject.collapsed"
            style="font-size: 16px; color: #36454d; margin-right: 10px"
            @click="proLayoutObject.collapsed = false"
          />
          <MenuFoldOutlined
            v-else
            style="font-size: 16px; color: #36454d; margin-right: 10px"
            @click="proLayoutObject.collapsed = true"
          />
          <ReloadOutlined
            style="font-size: 16px; color: #36454d"
            :spin="!isRouterAlive"
            @click="routeReload"
          />
        </div>

        <!-- 面包屑部分。数组第一项固定为首页，可以点击跳转，其他面包屑，不允许进行跳转 -->
        <a-breadcrumb style="margin-left: 10px">
          <a-breadcrumb-item>
            <router-link :to="breadcrumb[0].path">
              {{ breadcrumb[0].breadcrumbName }}
            </router-link>
          </a-breadcrumb-item>
          <a-breadcrumb-item
            v-for="(item, index) in breadcrumb"
            v-show="item.path !== '/'"
            :key="index"
          >
            {{ item.breadcrumbName }}
          </a-breadcrumb-item>
        </a-breadcrumb>
      </div>
    </template>
    <!-- 自定义右侧区域 -->
    <template #rightContentRender>
      <div class="wechat-content">
        <div class="but-main" @click="open()">获取{{ $SYS_NAME_MAP.MCH_APP }}APP/小程序</div>
      </div>
      <div class="right-content">
        <!-- <div class="text-align" @click="mchNotice">安全教育</div> -->

        <div
          v-if="$access('ENT_C_QUICKCASHIER')"
          class="text-align"
          @click="openQuickCollection"
        >
          快捷收银
        </div>

        <a-dropdown>
          <template #overlay>
            <a-menu>
              <a-menu-item @click="userInfo">
                <setting-outlined style="margin-right: 10px" /><span
                  style="cursor: hand"
                >个人信息</span>
              </a-menu-item>
              <a-menu-item @click="logout">
                <LogoutOutlined style="margin-right: 10px" /><span
                  style="cursor: hand"
                >退出登录</span>
              </a-menu-item>
            </a-menu>
          </template>
          <a-avatar
            shape="square"
            class="square"
            :src="userStore.userInfo.avatarUrl"
          />
        </a-dropdown>
        <span class="text-align">{{ userStore.userInfo['realname'] }}</span>
      </div>
    </template>
  </pro-layout>

  <QuickCollection ref="QuickCollectionRef" />

  <a-modal
    v-model:visible="vdata.visible"
    title="安全教育"
    :footer="null"
    width="55%"
  >
    <div style="height: 60vh; overflow: auto" v-html="modalContent" />
  </a-modal>
  <previewImg ref="refPreImg" />
</template>

<script setup lang="ts">
import { useRouter, useRoute } from 'vue-router'
import { useUserStore } from '@/store/modules/user'
import previewImg from'./components/previewImg.vue'
import {
  onMounted,
  ref,
  reactive,
  computed,
  watchEffect,
  nextTick,
  getCurrentInstance
} from 'vue'
import { useOem } from '@/store/modules/oem' // OEM信息
import { getMenuData, clearMenuItem } from '@ant-design-vue/pro-layout'
import QuickCollection from '@/views/quickCollection/QuickCollection.vue'
const { $access, $infoBox, $SYS_NAME_MAP } = getCurrentInstance()!.appContext.config.globalProperties
// 获取网站信息
const oemSiteInfo = useOem().getSiteInfo()

// 响应式数据
const vdata = reactive({
  openKeys: [] as any,
  selectedKeys: [] as any,
  theme: 'light', //light or dark
  visible: false // 公告对话框
})

// proLayout对象
const proLayoutObject = reactive({
  collapsed: false
})
// 获取二维码预览组件实例
const refPreImg :any = ref(null)
/* 
  商户公告
*/
let modalContent = ref(`
<div style="text-align:center;"><strong>条码商户安全教育</strong></div>
&nbsp; &nbsp; &nbsp; &nbsp; 条码支付就是通过扫条形码完成支付，包括条形码支付和二维码支付，分为“主扫”和“被扫”两种形式。“主扫”又称付款扫码，是消费者扫商户的二维码消费，支付金额由消费者手动输入或商户手工输入。以下针对“主扫”即付款扫码支付方式，主要从条码支付安全知识、安全风险及风险防范措施等方面对条码商户进行普及和提示。<br />
<p>条码分为静态条码和动态条码。静态条码长期有效，商家贴在柜台上的即为静态条码，在菜场、小商贩等小店使用较多；动态条码时时变动，安全性较高，在商场、便利店商家主扫付款时会用到的动态条码。</p>
<p><br /></p>
<strong>一、 静态条码</strong><br /><strong>1. 支付安全知识和风险提示：</strong><br />静态条码在开放互联网环境下以图形化方式进行展示，不法分子可通过截屏、偷拍等手段盗取支付凭证，易被篡改和变造，宜携带木马或病毒，易被覆盖，真伪难辨，导致支付风险较高，容易造成资金受损。<br /><strong>2. 风险防范措施：</strong><br />（1）静态条码应采用防伪纸张展示条码，最好采用防护罩等物理防护手段避免条码被覆盖或替换，且使用防伪标签对防护罩进行标记；<br />（2）静态条码的介质应放置在收银员视线范围内，并定期对介质进行检查是否被替换；<br />（3）静态条码介质应放置在显著位置，且明显展示收款方信息，便于消费者核对；<br />（4）通过正规合法渠道下载收款软件，开启支付成功之后语音提示付款成功功能；<br />（5）要求消费者付款之后展示支付成功证明，在查看付款证明时应核对清楚收款方信息及收款金额等。<br /><strong>二、动态条码</strong><br /><strong>1． 支付安全知识和风险提示：</strong><br />动态条码相比静态条码安全等级相对较高，但在实际支付过程中也不能掉以轻心。<br />2． 风险防范措施：<br />（1） 对于每笔交易，商户需确认收到收单机构语音到账提示或其他到账通知后才能确认收款到账，避免仅使用消费者的扣款通知作为商户到账通知；<br />（2）在收银区显著位置提示消费者注意核对收款方信息。<br /><br />`)
const mchNotice = () => (vdata.visible = true)

/*
 * 快捷收银
 */

const QuickCollectionRef = ref() // 获取快捷收银弹窗

const openQuickCollection = () => QuickCollectionRef.value.showModal() // 展开快捷收银

// 获取到路由对象
const router = useRouter() //这是全部路由
const route = useRoute() //这是当前页面的路由
// vdata.selectedKeys.push(route.path) //为selectedKeys赋值当前页面路由
// vdata.openKeys.push(route.matched[1].path) //为openKeys赋值当前路由所属菜单的展开项

//如果存在多级路由嵌套
if (route.matched.length > 3) {
  for (let i = 2; i < route.matched.length - 1; i++) {
    vdata.openKeys.push(route.matched[i].path)
  }
}

// store对象
const userStore = useUserStore()

// 使用pro-layout 封装menu对象信息
const { menuData } = reactive(getMenuData(clearMenuItem(router.getRoutes())))

// 判断路由是否可用状态（用作刷新使用）
let isRouterAlive = ref(true)

// 面包屑导航参数

const breadcrumb = computed(() =>
  router.currentRoute.value.matched.concat().map((item) => {
    return {
      path: item.path,
      breadcrumbName: item.meta.title || ''
    }
  })
)
watchEffect(() => {
  if (router.currentRoute) {
    const matched = router.currentRoute.value.matched.concat()

    vdata.selectedKeys = matched
      .filter((r) => r.name !== 'index')
      .map((r) => r.path)
    vdata.openKeys = matched
      .filter((r) => r.path !== router.currentRoute.value.path)
      .map((r) => r.path)
  }
})
// 刷新页面函数
function routeReload() {
  isRouterAlive.value = false
  nextTick(() => {
    isRouterAlive.value = true
  })
}

// 登出函数
function logout() {
  $infoBox.confirmDanger(
    '是否退出登录？',
    `你好${userStore.userInfo['realname']}确认退出登录吗？`,
    () => {
      userStore.logout()
    }
  )
}
//个人信息页
function userInfo() {
  router.push({
    path: '/current/userinfo'
  })
}
const open =()=>{
  refPreImg.value.open()
}
</script>

<style scoped lang="less">
#collapsed {
  background: #000;
}
.test {
  width: 79px;
  height: 40px;
  background: #dddddd;
  border-radius: 12px;
  margin-top: 5px;
}
.refash {
  display: flex;
  justify-content: center;
  align-items: center;
}
.customhead {
  display: flex;
  height: 100%;
  align-items: center;
}
</style>

<style lang="less">
.ant-menu {
  background: transparent;
}

.ant-layout-sider-children {
  //导航整体的右侧新增一条border
  border-right: 1px solid #08174212;
  background: transparent;
  padding-bottom: 30px;
}
.ant-layout-sider-light {
  //亮色模式下整体的背景色
  background: @background-color;
}
.ant-pro-sider-light {
  //取消导航栏投影
  box-shadow: none !important;
}
.ant-pro-sider-logo {
  // 顶部logo的padding
  padding: 25px !important;
}
.ant-pro-sider-menu {
  //导航内容区域两边新增padding，并去掉了右侧的border
  padding: 0 15px !important;
  border: none !important;
}
.ant-menu-inline-collapsed {
  //收起状态下，导航内容区域两侧的padding变小
  padding: 0 10px !important;
}
.ant-menu-submenu-title {
  //使导航在收起状态下，带有子item的一级菜单的图标居中
  margin: 0 auto;
}
.ant-menu-item {
  margin: 0 auto !important; //使导航在收起状态下，没有子item的一级菜单图标居中
  border-radius: 3px;
  &:hover {
    background: @primary-glass; //导航item的hover样式
  }
}
.ant-menu-sub.ant-menu-inline > .ant-menu-item {
  //二级导航item的上下边距
  margin: 5px 0 !important;
}
.ant-menu-vertical.ant-menu-sub {
  //收起状态下，子菜单的容器padding
  padding: 5px;
}
.ant-menu-dark .ant-menu-inline.ant-menu-sub {
  //暗色模式下，子菜单背景颜色调整
  background: #001529;
}
.ant-menu-sub.ant-menu-inline {
  //亮色模式下，子菜单背景颜色调整
  background-color: @background-color;
}
.ant-pro-sider-light .ant-layout-sider-children ::-webkit-scrollbar-track {
  //亮色状态下，去掉滚动条轨道颜色
  background: transparent;
}
.ant-pro-sider-dark .ant-layout-sider-children ::-webkit-scrollbar-track {
  //暗色状态下，去掉滚动条轨道颜色
  background: transparent;
}
.ant-pro-sider .ant-layout-sider-children ::-webkit-scrollbar-track {
  //去掉滚动条轨道的内阴影
  box-shadow: none;
}
.ant-menu:not(.ant-menu-horizontal) .ant-menu-item-selected {
  //选中状态下的item的样式
  background-color: var(--ant-primary-color) !important;
  color: #fff !important;
  border-radius: 3px;
  & a:hover {
    color: #fff !important;
  }
}
.ant-menu-item-selected a {
  //选中状态下的文字颜色继承父元素
  color: inherit !important;
}
.ant-menu-item .ant-menu-item-icon + span {
  //去掉文字变色的延迟动画效果
  transition: 0s;
}
.ant-menu-vertical .ant-menu-item::after,
.ant-menu-vertical-left .ant-menu-item::after,
.ant-menu-vertical-right .ant-menu-item::after,
.ant-menu-inline .ant-menu-item::after {
  //取消选中状态下item右侧的蓝色方条
  content: none;
}

//header样式
.ant-layout-header {
  background-color: transparent;
  height: auto !important;
  width: 100%;
  padding: 25px 0 !important;
  line-height: inherit !important;
}
.ant-pro-global-header {
  padding: 0 30px !important;
  background-color: transparent;
  box-shadow: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

aside {
  max-width: 300px;
}

aside::before {
  // content: '';
  position: absolute;
  background-color: @jee-theme;
  width: 10px;
  height: 100vh;
  left: 0;
  top: 0;
  z-index: 99;
}
.ant-pro-basicLayout-content {
  position: relative;
  margin: 0 15px;
}

// 菜单底部按钮
.menu-footer {
  cursor: pointer;
  height: 36px;
  margin: 0 25px;
  border-radius: 3px;
  background: rgba(235, 238, 242, 0);
  border: 1px dashed #d2d3d9;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #7a8a99;
  transition: 0.3s ease;
  &:hover {
    border: 1px dashed var(--ant-primary-color);
    color: var(--ant-primary-color);
    background: @primary-glass;
  }
  .bi-circle-half {
    transform: rotate(45deg);
    transition: 0.2s ease;
  }
  span {
    font-weight: normal;
    font-size: 14px;
    letter-spacing: 0.05em;
    text-align: left;
    margin-left: 7px;
    transition: 0.2s ease;
  }
}

.menu-footer-dark {
  height: 36px;
  border-radius: 3px;
  background: rgba(235, 238, 242, 0);
  border: 1px dashed #4d5c6a;
  color: #fff;
  .bi-circle-half {
    transform: rotate(225deg);
  }
}

.right-content {
  display: flex;
}
.text-align {
  margin-right: 35px;
  font-size: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
  &:hover {
    cursor: pointer;
  }
}

.square {
  margin-right: 5px;
  width: 30px;
  height: 30px;
  &:hover {
    cursor: pointer;
  }
}
</style>
<style>
.ant-pro-sider-menu {
  background-color: transparent !important;
  overflow: hidden !important;
}
.ant-pro-menu-item:hover {
  color: var(--ant-primary-color) !important;
}
.ant-layout-header {
  background-color: transparent !important;
  padding: 0 !important;
}
.ant-pro-global-header-layout-side {
  background-color: transparent !important;
  box-shadow: none !important;
  padding: 25px 25px !important;
}
.ant-pro-sider .ant-layout-sider-children {
  height: 100vh !important;
}
.ant-layout-content {
  margin: 0 15px 24px 15px !important;
}
.ant-layout:first-child .ant-layout {
  height: 100vh !important;
  overflow-y: scroll !important;
}
.wechat-content {
  margin: 0 30px;
}
.but-main {
  background-color: rgba(0, 0, 0, .03);
  color: #666;
  border-radius: 5px;
  padding: 8px 28px;
  cursor: pointer;
}
</style>
